<?php

class SelfDashboardController extends SelfController {

	/*
	|--------------------------------------------------------------------------
	| Default Home Controller
	|--------------------------------------------------------------------------
	|
	| You may wish to use controllers instead of, or in addition to, Closure
	| based routes. That's great! Here is an example controller method to
	| get you started. To route to this controller, just add the route:
	|
	|	Route::get('/', 'HomeController@showWelcome');
	|
	*/
    private $foodService = null;
    private $orderService = null;

	public function getIndex()
	{

        $result =  $this->getFoodService()->getList(array(), 8);
        $entries = $result['entries'];
        $links = $result['links'];

        $menu_id = Input::get( 'menu_id', null );
        $title = '全部餐品';
        if(!empty($menu_id)){
            $title = Menu::where('id', $menu_id)->select('name')->get()->first()->name;
        }

        return View::make(self::$view_path.'.dashboard', compact('entries','title', 'links'));
	}

    /**
     * 下单
     */
//    public function doCreate(){
//        $foodIds = Input::get('food_ids');
//        $counts = Input::get('counts');
//        $totalPrice = Input::get('total_price');
//
//        if(!is_array($foodIds)){
//            return json_encode(array('result'=>false, 'msg'=>'不允许生成空订单！'));
//        }
//
//        $result = $this->getOrderService()->createOrder($this->member, $foodIds, $counts, $totalPrice);
//        if(!$result){
//            return json_encode(array('result'=>false, 'msg'=>$this->getOrderService()->errors()->getMessages()));
//        }
//        return json_encode(array('result'=>true, 'msg'=>'下单成功！', 'order_id'=>$result));
//    }

    public function getOrderService() {
        if(is_null($this->orderService)){
            $this->orderService = new SelfOrderService();
        }
        return $this->orderService;
    }

    public function getFoodService() {
        if(is_null($this->foodService)){
            $this->foodService = new SelfFoodService();
        }
        return $this->foodService;
    }
}